import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/providers/user_profile.dart';
import 'package:tender_flutter/router/router.dart';
import 'package:tender_flutter/router/router_map.gr.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/widgets/icon_text_view.dart';

class FreePermissionDialog extends StatefulWidget {
  @override
  _FreePermissionDialogState createState() => _FreePermissionDialogState();
}

class _FreePermissionDialogState extends State<FreePermissionDialog> {
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: _initBody(),
        onWillPop: () {
          pop();
          return Future.value(false);
        });
  }

  Widget _initBody() {
    return Scaffold(
        backgroundColor: Colors.transparent,
        body: Center(
            child: Container(
          width: ScreenAdapter.width(650),
          child: Column(mainAxisSize: MainAxisSize.min, children: [
            Container(
              height: ScreenAdapter.height(640),
              //设置背景图片
              decoration: new BoxDecoration(
                image: DecorationImage(
                  image: ExactAssetImage(
                      RPath.imgPath + "img_dialog_free_per_bg.png"),
                ),
              ),
              child: Stack(
                alignment: Alignment.center,
                children: [
                  Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        SizedBox(height: ScreenAdapter.height(60)),
                        Consumer(builder: (BuildContext ctx,
                            UserProfileInfo profileInfo, Widget child) {
                          return Text(profileInfo.userInfo != null ? "您的每天${profileInfo.userInfo.tyTime}条免费权限用完啦" : "您的免费权限用完啦",
                              style: TextStyle(
                                  color: ThemeColors.colorWhite,
                                  fontSize: ScreenAdapter.sp(30),
                                  fontWeight: FontWeight.bold));
                        }),
                        SizedBox(height: ScreenAdapter.height(10)),
                        Text(" 开通会员 掌握更多商机信息",
                            style: TextStyle(
                              color: ThemeColors.colorWhite,
                              fontSize: ScreenAdapter.sp(24),
                            )),
                      ]),
                  Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(height: ScreenAdapter.height(330)),
                        IconText(
                          "查看更多商机信息",
                          icon: Image.asset(
                              RPath.imgPath + "icon_permission_box.png",
                              fit: BoxFit.contain,
                              width: ScreenAdapter.width(25),
                              height: ScreenAdapter.width(25)),
                          padding:
                              EdgeInsets.only(right: ScreenAdapter.width(5)),
                          style: TextStyle(
                            color: ThemeColors.colorType14,
                            fontSize: ScreenAdapter.sp(24),
                          ),
                        ),
                        SizedBox(height: ScreenAdapter.height(15)),
                        IconText(
                          "轻松与采购方取得联系",
                          iconSize: ScreenAdapter.width(25),
                          icon: Image.asset(
                              RPath.imgPath + "icon_permission_box.png",
                              fit: BoxFit.contain,
                              width: ScreenAdapter.width(25),
                              height: ScreenAdapter.width(25)),
                          padding:
                              EdgeInsets.only(right: ScreenAdapter.width(5)),
                          style: TextStyle(
                            color: ThemeColors.colorType14,
                            fontSize: ScreenAdapter.sp(24),
                          ),
                        ),
                        SizedBox(height: ScreenAdapter.height(15)),
                        IconText(
                          "订阅项目及时推送，永不漏标",
                          iconSize: ScreenAdapter.width(25),
                          icon: Image.asset(
                              RPath.imgPath + "icon_permission_box.png",
                              fit: BoxFit.contain,
                              width: ScreenAdapter.width(25),
                              height: ScreenAdapter.width(25)),
                          padding:
                              EdgeInsets.only(right: ScreenAdapter.width(5)),
                          style: TextStyle(
                            color: ThemeColors.colorType14,
                            fontSize: ScreenAdapter.sp(24),
                          ),
                        ),
                        SizedBox(height: ScreenAdapter.height(15)),
                        IconText(
                          "供需信息发布，置顶显示",
                          iconSize: ScreenAdapter.width(25),
                          icon: Image.asset(
                              RPath.imgPath + "icon_permission_box.png",
                              fit: BoxFit.contain,
                              width: ScreenAdapter.width(25),
                              height: ScreenAdapter.width(25)),
                          padding:
                              EdgeInsets.only(right: ScreenAdapter.width(5)),
                          style: TextStyle(
                            color: ThemeColors.colorType14,
                            fontSize: ScreenAdapter.sp(24),
                          ),
                        ),
                      ]),
                  Align(
                      alignment: Alignment.bottomCenter,
                      child: Container(
                        width: ScreenAdapter.width(260),
                        height: ScreenAdapter.height(60),
                        margin:
                            EdgeInsets.only(bottom: ScreenAdapter.height(40)),
                        decoration: BoxDecoration(
                          color: Colors.white,
                          image: DecorationImage(
                              image: AssetImage(
                                  RPath.imgPath + "img_free_dialg_btn.png"),
                              fit: BoxFit.fill),
                        ),
                        alignment: Alignment.center,
                        child: FlatButton(
                          onPressed: () {
                            LRouter.navigatorCtx(context)
                                .popAndPush(Routes.memberCentrePage);
                          },
                          child: Text("了解更多权益",
                              style: TextStyle(
                                color: ThemeColors.colorWhite,
                                fontSize: ScreenAdapter.sp(24),
                              )),
                          color: Colors.transparent,
                        ),
                      ))
                ],
              ),
            ),
            SizedBox(height: ScreenAdapter.height(60)),
            FlatButton(
                onPressed: () {
                  pop();
                },
                child: Image.asset(
                  RPath.imgPath + "icon_dialog_close.png",
                  fit: BoxFit.contain,
                  width: ScreenAdapter.width(60),
                  height: ScreenAdapter.width(60),
                )),
          ]),
        )));
  }

  void pop() {
    LRouter.navigatorCtx(context).pop();
  }
}
